package delasell.adressBook.view;


import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

import java.awt.*;


public class MainFrame extends JFrame {
	

	protected static JPanel mainPanel;
	protected static JPanel leftPanel;
	protected static JPanel rightPanel;
	protected static JPanel menuPanel;
	protected static JPanel contactPanel;
	
	protected static JButton newButton;
	protected static JButton editButton;
	protected static JButton deleteButton;
	protected static JButton saveButton;
	protected static JButton openButton;
	
	protected static JScrollPane scrollPane;
	protected static JTable contactList;
	protected String[] tableHeader;
	
	protected static JLabel persAdressLabel;
	protected static JLabel compAdressLabel;
	protected static JLabel persPhoneLabel;
	protected static JLabel compPhoneLabel;
	protected static JLabel webLabel;
	protected static JLabel emailLabel;
	
	
	protected static JLabel nameDisplay;
	protected static JLabel firstNameDisplay;
	protected static JLabel persAdressDisplay;
	protected static JLabel compAdressDisplay;
	protected static JLabel[] persPhoneDisplay;
	protected static JLabel[] compPhoneDisplay;
	protected static JLabel webDisplay;
	protected static JLabel emailDisplay;
	
	
	public MainFrame()
	{
		//PANELS
		
		mainPanel = new JPanel();
		
		leftPanel = new JPanel();
		leftPanel.setPreferredSize(new Dimension(300, 768));
		rightPanel= new JPanel();
		rightPanel.setPreferredSize(new Dimension(650, 768));
		menuPanel = new JPanel();
		menuPanel.setPreferredSize(new Dimension(650, 100));
		contactPanel = new JPanel();
		contactPanel.setPreferredSize(new Dimension(650, 668));
		
		newButton = new JButton("New");
		editButton = new JButton("Edit");
		deleteButton = new JButton("Delete");
		saveButton = new JButton("Save");
		openButton = new JButton("Open");
		
		Dimension dim = new Dimension(80, 30);
		newButton.setPreferredSize(dim);
		editButton.setPreferredSize(dim);
		deleteButton.setPreferredSize(dim);
		saveButton.setPreferredSize(dim);
		openButton.setPreferredSize(dim);
	
		
		//ScrollPane
		scrollPane = new JScrollPane();
		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);		
		
		leftPanel.add(scrollPane, BorderLayout.PAGE_START);
		tableHeader = new String[3];
		tableHeader[0] = "Name";
		tableHeader[1]= "First Name";
		tableHeader[2]= "3rd Row";
		
		String[][] testElement = {
									{"Richard", "Antoine", "blop"},
									{"LeNoan", "Pierre", "Plob"}
								};
		
		contactList = new JTable(testElement, tableHeader);
		//contactList.setEnabled(false);		
		
		TableModel mainModel = new TableModel();
		//contactList.setModel(mainModel);
		contactList.setAutoCreateRowSorter(true);
		scrollPane.getViewport().add(contactList);
		
		
		
		scrollPane.setPreferredSize(new Dimension(300, 700));
		contactList.setPreferredSize(new Dimension(300, 670));
		
		
		
		
		
		//LABELS
		
		persAdressLabel = new JLabel("Personal Adress");
		compAdressLabel = new JLabel("Company Adress");
		persPhoneLabel = new JLabel("Personal Phone");
		compPhoneLabel = new JLabel("Company PHone");
		webLabel = new JLabel("Web Profile");
		emailLabel = new JLabel("Email");
		
		nameDisplay = new JLabel("defaultName");
		firstNameDisplay= new JLabel("defaultFirst");
		persAdressDisplay = new JLabel("default Adress");
		compAdressDisplay = new JLabel("default comp Adress");
		persPhoneDisplay = new JLabel[2];
		persPhoneDisplay[0] = new JLabel("pers Phone 1");
		persPhoneDisplay[1] = new JLabel("pers Phone 2");
		compPhoneDisplay = new JLabel[2];
		compPhoneDisplay[0] = new JLabel("comp Phone 1");
		compPhoneDisplay[1] = new JLabel("comp Phone 2");
		webDisplay = new JLabel("example.com");
		emailDisplay = new JLabel("example@example.com");
		
		//FONTS
		
		Font bigFont = new Font(webLabel.getFont().getName(), webLabel.getFont().getStyle(), 35);
		Font mediumFont = new Font(webLabel.getFont().getName(), webLabel.getFont().getStyle(), 15);
		nameDisplay.setFont(bigFont);
		firstNameDisplay.setFont(bigFont);
		
		persAdressLabel.setFont(mediumFont);
		compAdressLabel.setFont(mediumFont);
		persPhoneLabel.setFont(mediumFont);
		compPhoneLabel.setFont(mediumFont);
		webLabel.setFont(mediumFont);
		emailLabel.setFont(mediumFont);
		
		// LAYOUT
		
		mainPanel.setLayout(new FlowLayout());
		mainPanel.add(leftPanel);
		mainPanel.add(rightPanel);
		
		rightPanel.add(menuPanel, BorderLayout.PAGE_START);
		rightPanel.add(contactPanel, BorderLayout.PAGE_END);
		
		menuPanel.add(newButton, BorderLayout.LINE_START);
		menuPanel.add(editButton, BorderLayout.LINE_START);
		menuPanel.add(deleteButton,BorderLayout.LINE_START);
		menuPanel.add(saveButton, BorderLayout.LINE_END);
		menuPanel.add(openButton, BorderLayout.LINE_END);
		
		contactPanel.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		
		c.gridx=0;
		c.gridy=0;
		c.gridheight=1;
		c.gridwidth=2;
		c.ipady=40;
		c.insets = new Insets(10,10,30,30);
		c.anchor=GridBagConstraints.PAGE_START;
		c.fill = GridBagConstraints.VERTICAL;
		contactPanel.add(nameDisplay, c);
		
		c.gridx=2;
		contactPanel.add(firstNameDisplay,c);
		
		c.gridx=0;
		c.gridy=1;
		c.gridheight=1;
		c.gridwidth=1;
		contactPanel.add(persAdressLabel,c);
		
		c.gridx=1;
		c.gridy=1;
		contactPanel.add(persAdressDisplay,c);
		
		c.gridx=2;
		c.gridy=1;
		contactPanel.add(compAdressLabel,c);
		
		c.gridx=3;
		c.gridy=1;
		contactPanel.add(compAdressDisplay,c);
		
		c.gridx=0;
		c.gridy=2;
		c.gridheight=2;
		contactPanel.add(persPhoneLabel,c);
		
		c.gridx=2;
		c.gridy=2;
		contactPanel.add(compPhoneLabel,c);
		
		c.gridx=1;
		c.gridy=2;
		c.gridheight=1;
		contactPanel.add(persPhoneDisplay[0],c);
		
		c.gridx=1;
		c.gridy=3;
		contactPanel.add(persPhoneDisplay[1],c);
		
		c.gridx=3;
		c.gridy=2;
		contactPanel.add(compPhoneDisplay[0],c);
		
		c.gridx=3;
		c.gridy=3;
		contactPanel.add(compPhoneDisplay[1],c);
		
		c.gridx=0;
		c.gridy=4;
		contactPanel.add(webLabel,c);
		
		c.gridx=2;
		c.gridy=4;
		contactPanel.add(emailLabel,c);
		
		c.gridx=1;
		c.gridy=4;
		contactPanel.add(webDisplay,c);
		
		c.gridx=3;
		c.gridy=4;
		contactPanel.add(emailDisplay,c);
		
		contactPanel.setBackground(Color.WHITE);
		
		mainPanel.setLayout(new FlowLayout());
		setTitle("Adress Book");
	    setSize(1024, 768);
	    this.setResizable(false);
	    setLocationRelativeTo(null);
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
	    
	    this.setContentPane(mainPanel);
	    
	}


	public static JButton getNewButton() {
		return newButton;
	}


	public static JButton getEditButton() {
		return editButton;
	}


	public static JButton getDeleteButton() {
		return deleteButton;
	}


	public static JButton getSaveButton() {
		return saveButton;
	}


	public static JButton getOpenButton() {
		return openButton;
	}


	public static JLabel getNameDisplay() {
		return nameDisplay;
	}


	public static JLabel getFirstNameDisplay() {
		return firstNameDisplay;
	}


	public static JLabel getPersAdressDisplay() {
		return persAdressDisplay;
	}


	public static JLabel getCompAdressDisplay() {
		return compAdressDisplay;
	}


	public static JLabel[] getPersPhoneDisplay() {
		return persPhoneDisplay;
	}


	public static JLabel[] getCompPhoneDisplay() {
		return compPhoneDisplay;
	}


	public static JLabel getWebDisplay() {
		return webDisplay;
	}


	public static JLabel getEmailDisplay() {
		return emailDisplay;
	}


	public static JScrollPane getScrollPane() {
		return scrollPane;
	}


	public static JTable getContactList() {
		return contactList;
	}

}
